<script setup lang="ts">
import {Search} from "@element-plus/icons-vue";
import {ref} from "vue";
import {reqHospitalInfo} from "@/api/home";
import type {HospitalInfo,Content} from "@/api/home/type";
import {useRouter} from "vue-router";
//收集搜索的关键字（医院的名字）
let hosname=ref<string>('');
//创建路由对象
let $router = useRouter();
//顶部组件的回调
const fetchData= async (keyword:string,cb:any)=>{
  let result: HospitalInfo = await reqHospitalInfo(keyword);
  let showData = result.data.map(item=>{
    return {
      value:item.hosname,
      hoscode:item.hoscode
    }
  })
  cb(showData);
}
//点击某一个推荐项
const goDetail =(item:any)=>{
  console.log(item);
  //点击推荐项目进行人民医院详情页，将来需要携带query参数
  $router.push({path:'/hospital/register',query:{hoscode:item.hoscode}})
}

</script>
<script lang="ts">
export default {
  name:"Search"
}
</script>
<template>
<div class="search">
  <el-autocomplete
      :trigger-on-focus="false"
      clearable
      class="inline-input w-50"
      placeholder="请输入医院名称"
      :v-model="hosname"
      :fetchSuggestions="fetchData"
      @select="goDetail"
  />
  <el-button type="primary" :icon="Search">搜索</el-button>
</div>
</template>

<style scoped lang="scss">
.search{
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 10px 0px;
  //深度选择器
  ::v-deep(.el-input__wrapper){
    margin-right: 10px;
  }
}
</style>
